class Admin::LeaguesController < Admin::BaseController
  def index
    @leagues = League.paginate :page=>params[:page]
  end

  def edit
    @league = League.find params[:id]
  end

  def update
    @league = League.find params[:id]
    if @league.update_attributes params[:league]
      flash[:notice]='created successful'
      redirect_to admin_leagues_path
    else
      render :action=>'edit'
    end
  end

  def fetch_matches
    @league = League.find params[:id]
    matches = @league.fetch_matches
    flash[:notice] = "success fetched #{matches.size} matches"
    redirect_to admin_leagues_path
  end

  def fetch_results
    @league = League.find params[:id]
    matches = @league.fetch_results
    redirect_to admin_leagues_path
  end

  def destroy
    @league = League.find params[:id]
    @league.destroy
    flash[:notice] = 'deleted successful'
    redirect_to admin_leagues_path
  end

  def create
    @league = League.new params[:league]
    if @league.save
      flash[:notice]= 'created successful'
      redirect_to admin_leagues_path
    else
      render :action=>'new'
    end
  end

  def new
    @league = League.new
  end
  
end
